﻿/*
 *  Source code courtesy of the desktopWeb.CodePlex.com community project. See MS-PL license on Codeplex.com. 
 *  This is beta code not intended for a production application.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Windows.Documents;
using System.Windows.Controls;
using System.Activities.Presentation;
using System.Activities.Presentation.Model;
using System.Activities.Presentation.View;

namespace MyData.Common
{
  public static class EventLogEntryExtensions
  {
    public static string MessageLine(this EventLogEntry eventLogEntry)
    {
      return eventLogEntry.Message.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)
        [1].Replace("Message:", string.Empty);
    }
  }

  public static class ExpressionTextBoxExtensions
  {
    public static string ExpressionPath(this ExpressionTextBox etb)
    {
      return etb.GetBindingExpression(ExpressionTextBox.ExpressionProperty).ParentBinding.Path.Path;
    }
  }

  public static class RichTextBoxExtensions
  {
    public static string DocumentText(this RichTextBox richTextBox)
    {
      TextRange range;
      range = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);

      return range.Text;
    }
    public static void DocumentText(this RichTextBox richTextBox, string text)
    {
      TextRange range;
      range = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);

      range.Text = text;
    }
  }

  public static class StringExtensions
  {
    public static string QuotedValue(this String value)
    {
      value = value != null ? value : string.Empty;
      return "\"" + value + "\"";
    }
  }

}
